﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace BlogApi.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
            .ToArray();
            //这段是自定义返回的JSON字符串
            //var list = new List<WeatherForecast>();
            //for (int i = 0; i < 10; i++)
            //{
            //    list.Add(new WeatherForecast()
            //    {
            //        Date = DateTime.Now,
            //        TemperatureC = new Random().Next(1, 10),
            //        Summary = Summaries[new Random().Next(Summaries.Length)]
            //    });
            //}
            //return new JsonResult(new
            //{
            //    code = 0,
            //    userInfo = new
            //    {
            //        userImg = "https://hatsune-miku-yyy-blog-static.oss-cn-chengdu.aliyuncs.com/userImages/miku3.jpg",
            //        userNickName = "Hatsune_Miku_YYY",
            //        fanNumber = "@integer(100, 300)",
            //        description = "这人太懒了啥也没写",
            //        userTagList = list
            //    }
            //});
        }
    }
}
